# -*- coding:utf-8 -*-
#import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')

import os,datetime
now_path=os.path.abspath('.').replace('\\','/')

log_file=now_path+'/xuliehua.json'
class C(object):
    cc='cc'
    list_c=['c','c']
class B(object):
    bb=9
    list_b=['b','b']
    c=C()
    list_c_object=[C()]*5
    bzn='中文'
class A(object):
    '''int、string、Boolean、long、double,arraylist、object、DateTime、'''
    i=1
    s='a'
    szn='中文'
    b=True
    li=[1,2,3]
    o=B()
    dt=datetime.datetime.now()
    l=9999L
    f=1.1

    def say_hi(self):
        print 'hi'
    def set_ii(self):
        self.ii=123
coding_list=['utf-8', 'gb2312', 'gbk', 'gb18030', 'cp1252', ]
def decode_str(data):
    for coding in coding_list:
        try:
            rdata=data.decode(coding)
            return rdata
        except:
            pass
    return u''
def decode_attr(tobject,svalue):
    if str(svalue).startswith('__'):
        return ''
    if hasattr(tobject,str(svalue)):
        value=getattr(tobject,str(svalue))
    else:
        value=svalue
    if '__call__' in dir(value):
        return ''
    if type(value) in (type(1),type(True),type(1L),type(1.0)):
        return value
    elif type(value)==type('s'):
        print str(decode_str(value))
        return decode_str(value).encode('gbk')
    elif type(value)==type([1]):
        return_list=[]
        for i in value:
            return_list.append(decode_attr(value,i))
        return return_list
    elif type(value)==type(datetime.datetime.now()):
        return str(value)        
    elif '__class__' in dir(value):
        return decode_object(value)
    return ''


def decode_object(tobject):
    value_list=dir(tobject)
    #print value_list
    w_value_dic={}
    for svalue in value_list:
        js_str=decode_attr(tobject,svalue)
        if js_str:
            w_value_dic[svalue]=js_str
    #print w_value_dic
    return w_value_dic

a=A()
a.set_ii()
w_value_dic=decode_object(a)
json_str=str(w_value_dic).replace("'",'"')

for key,value in w_value_dic.items():
    print key,value
print '='*50
print json_str
f=open(log_file,'w')
f.write(json_str)
s=str('\n中文')
f.write(s)
f.close()










